RDC sample application

To migrate this application to the RDC, remove the OCX component from Form1, and remove the Crystal Report Control from the Project|Components menu, in addition to the steps below:

Project|References

Reference the Crystal Report 8 ActiveX Designer Runtime Library

Project|Components

Crystal Report Viewer Control

Add a second form

Add the Crystal Report Viewer Control to Form2

The properties and methods are accessed from individual objects. Following this code sample is a detailed description on the RDC Automation Servers Object Model.

The RDC will open a standard Crystal Report (.RPT). The Report could have been Imported into or recreated in the RDC ActiveX Designer (.DSR).

Form1:

Declare the application object used to open the rpt file.

Dim crxApplication As New CRAXDRT.Application

Declare the report object.

Public Report As CRAXDRT.Report

Private Sub Form_Load()

Declare a DatabaseTable object for setting the location of the database. This object will be used for the main and subreport.

Dim crxDatabaseTable As CRAXDRT.DatabaseTable

Declare a ParameterFieldDefinition object for passing parameters.

Dim crxParameterField As CRAXDRT.ParameterFieldDefinition

Declare a Report object to set to the subeport.

Dim crxSubreport As CRAXDRT.Report

Declare a FormulaFieldDefinition object for passing formulas.

Dim crxFormulaField As CRAXDRT.FormulaFieldDefinition

Open the report.

Set Report = crxApplication.OpenReport _

(App.Path & "\OCX_to_RDC.rpt", 1)

Use a For Each loop to change the location of each DatabaseTable in the Reports DatabaseTable Collection.

For Each crxDatabaseTable In Report.Database.Tables

    crxDatabaseTable.Location = App.Path & "\xtreme.mdb"

Next crxDatabaseTable

Set crxParameterField to the first parameter in the parameterfields collection of the main report.

Set crxParameterField = Report.ParameterFields.Item(1)

Pass the value to the main report.

crxParameterField.AddCurrentValue "Main Report Parameter"

Set crxSubreport to the subreport 'Sub1' of the main report. The subreport name needs to be known to use this method.

Set crxSubreport = Report.OpenSubreport("Sub1")

Use a For Each loop to change the location of each DatabaseTable in the Subreport Database Table Collection.

For Each crxDatabaseTable In
    crxSubreport.Database.Tables

        crxDatabaseTable.Location = App.Path &
        "\xtreme.mdb"

Next crxDatabaseTable

Set crxFormulaField to the first formula in the formulafields collection of the subreport.

Set crxFormulaField = crxSubreport.FormulaFields.Item(1)

Pass the formula to the subreport.

crxFormulaField.Text = "'Subreport Formula'"

End Sub

Private Sub Command1_Click()

Call Form2 to preview the Report.

Form2.Show

End Sub

Private Sub Command2_Click()

Select the printer for the report passing the Printer Driver, Printer Name and Printer Port.

Report.SelectPrinter "HPPCL5MS.DRV", "HP LaserJet 4m Plus", "\\Vanprt\v1-1mpls-ts"

Print the Report without prompting the user.

Report.PrintOut False

End Sub

Private Sub Command3_Click()

Declare an ExportOptions Object.

Dim crxExportOptions As CRAXDRT.ExportOptions

Set crxExportOptions to the Report object's ExportOptions.

Set crxExportOptions = Report.ExportOptions

Set the report to be exported to Rich Text Format.

crxExportOptions.FormatType = crEFTRichText

Set the destination type to disk.

crxExportOptions.DestinationType = crEDTDiskFile

Set the path and name of the exported document.

crxExportOptions.DiskFileName = App.Path & "\RDCExport.rtf"

Export the report without prompting the user.

Report.Export False

End Sub

Form2:

Private Sub Form_Load()

Set the Report source for the Crystal Report Viewer to the Report.

CRViewer1.ReportSource = Form1.Report

'View the Report

CRViewer1.ViewReport

End Sub

Private Sub Form_Resize()

This code resizes the Report Viewer control to Form2's dimensions.

CRViewer1.Top = 0

CRViewer1.Left = 0

CRViewer1.Height = ScaleHeight

CRViewer1.Width = ScaleWidth

End Sub



Seagate Software IMG Holdings, Inc.
http://www.seagatesoftware.com
Support services:
http://support.seagatesoftware.com